• A realistic car simulation game featuring different sorts of cars (sports, sedan, hatchback, offroaders) and multiple tracks.
• It also contains smart opponent AI racing against the player, visual and performance damage upon collision, and different race modes.
• I have implemented the entirety of the project using Unity Engine and C#.
• This project is inspired by Forza Horizon and my love for cars.
• It also served as a learning project. I got to learn and implement car systems, vehicle physics and AI, and Unity mechanics such as Wheel Collider and Spring Joints.
• Implemented a realistic car behaviour following physics concepts such as aerodynamic-downforce and surface friction. The car's centre of mass is also adjusted to ensure stability at high speeds and each surface has different friction coefficients.
• Designed and sculpted levels and race tracks using Unity's Terrain tools and road building packages from Unity Asset Store.
• Programmed vehicle deformation and damage using Unity's Mesh Filters and Colliders.
• Created enemy AI and main game loop. The AI uses waypoints to navigate the track, it also avoids obstacles and other cars while attempting overtakes when possible.
• Created a polished camera systems using Cinemachine and AAA worthy main menu rendering using light baking techniques.
• Programmed and designed the UI.
void OnCollisionEnter(Collision collision)
{
float collisionPower = collision.impulse.magnitude;
if (collisionPower > minDamage)
{
foreach (ContactPoint point in collision.contacts)
{
for (int i = 0; i < meshVerticies.Length; i++)
{
Vector3 vertexPosition = meshVerticies[i];
Vector3 pointPosition = transform.InverseTransformPoint(point.point);
float distanceFromCollision = Vector3.Distance(vertexPosition, pointPosition);
float distanceFromOriginal = Vector3.Distance(startingVerticies[i], vertexPosition);
if (distanceFromCollision < deformRadius && distanceFromOriginal < maxDeform)
{
float falloff = 1 - (distanceFromCollision / deformRadius) * damageFalloff;
Vector3 deform = pointPosition * falloff;
deform = Vector3.Min(deform, Vector3.one * maxDeform);
meshVerticies[i] -= deform * damageMultiplier;
}
}
}
UpdateMeshVerticies();
}
}
void UpdateMeshVerticies()
{
filter.mesh.vertices = meshVerticies;
coll.sharedMesh = filter.mesh;
}
Full Script (GitHub)
The photos below will show erratic damage. It is the shortcoming of the models sourced from the Unity Asset Store. The damage system works best when the car is presented as a single mesh with a good amount of vertices. This will allow the code to accurately and smoothly deform the mesh.
Offroading:
Offroading:
Path Following AI:
Race Track (Inspired from the Grand Tour test track "Eboladrome"):
Damaged Car: